package com.guanghua.brick.html.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.Tag;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.guanghua.brick.html.CommonCell;
import com.guanghua.brick.html.ICell;
import com.guanghua.brick.html.IComponent;
import com.guanghua.brick.html.ILayout;

public class ContainCellTag extends BodyTagSupport implements IComponent {
	
	private static Log logger = LogFactory.getLog(ContainCellTag.class);
	private ICell cell = new CommonCell();
	
	public int doEndTag() throws JspException {
		//找到父亲，并add html
		Tag tag = this.getParent();
		if (tag instanceof ILayout) {
			cell.setBody((bodyContent != null)?bodyContent.getString():"&nbsp;");
			((ILayout)tag).appendCell(cell);
		} else {
			logger.warn("cell parent must be layout tag I and must be have body content");
		}
		
		
		return BodyTagSupport.EVAL_PAGE;
	}
	
	
	public String getBody() {
		return cell.getBody();
	}
	public int getCols() {
		return cell.getCols();
	}
	public int getEndColumn() {
		return cell.getEndColumn();
	}
	public int getEndRow() {
		return cell.getEndRow();
	}
	public String getHtml() {
		return cell.getHtml();
	}
	public String getId() {
		return cell.getId();
	}
	public String getName() {
		return cell.getName();
	}
	public int getRows() {
		return cell.getRows();
	}
	public int getStartColumn() {
		return cell.getStartColumn();
	}
	public int getStartRow() {
		return cell.getStartRow();
	}
	public void setBody(String body) {
		cell.setBody(body);
	}
	public void setCols(int cols) {
		cell.setCols(cols);
	}
	public void setEndColumn(int endColumn) {
		cell.setEndColumn(endColumn);
	}
	public void setEndRow(int endRow) {
		cell.setEndRow(endRow);
	}
	public void setHtml(String html) {
		cell.setHtml(html);
	}
	public void setId(String id) {
		cell.setId(id);
	}
	public void setName(String name) {
		cell.setName(name);
	}
	public void setRows(int rows) {
		cell.setRows(rows);
	}
	public void setStartColumn(int startColumn) {
		cell.setStartColumn(startColumn);
	}
	public void setStartRow(int startRow) {
		cell.setStartRow(startRow);
	}

}
